<?php session_start();
require '../common/Utility.php';
require '../db/configuration.php';
require '../crud/CustomSecurity.class.php';
require '../crud/Users.class.php';
loadDB();
isAdmin();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    <link rel="stylesheet" type="text/css" href="../css/page.css" />
    <link rel="stylesheet" type="text/css" href="../css/generalProduct.css" />
	<title>generalProduct</title>
	<meta name="generator" content="TextMate http://macromates.com/">
	<meta name="author" content="Dimtiar Giormov">
	
</head>
<body>	
<a class="lenta" href="index.php"> Начало </a>
<div id="main">



<?php
		require '../crud/Category.class.php';
		require '../crud/Vid_kolichestvo.class.php';
		require '../crud/GenProduct.class.php';
?>
		
	<form action="generalProduct.php" method="post">
	
	<ol>
	
	<li>Product Name: 
	<input class="table-input" type="text" name="pName"></li>
	<li> Category: 
<?php
		$crudCategory = new Category(con());
		$categs = $crudCategory->getAll();
		generateCombo($categs, 'categoryNew.php', 'category');
?>
	</li>
	<li>Quantity Type: 
<?php
	$quoType = new Vid_kolichestvo(con());
	$types = $quoType->getAll();
	generateCombo($types, '', 'quoType');
?>
	<input class="table-submit" type="submit" value="Add">
	</li>
	</ol>
	</form>
<?php
		$crud = new GenProduct($GLOBALS['connection']);

		if (isset($_POST['pName'])){
			$crud->add($_POST['pName'], $_POST['quoType'], $_POST['category'] );
		} else if(isset($_POST['Remove'])) {
			$crud->remove($_POST['id']);
		}
		$tableHeaders[0] = 'name';
		$tableHeaders[1] = 'category';
		$tableHeaders[2] = 'quantity';
		list_table_raw($crud->getAllAdmin(),'', $tableHeaders, 'General Product');

?>

</div>
</body>
</html>